//
//  ButtonItem.m
//  DragViewDemo
//
//  Created by 吳瀾洲 on 2020/8/19.
//  Copyright © 2020 kingboyrang. All rights reserved.
//

#import "ButtonItem.h"

@implementation ButtonItem


- (instancetype)initWithModel:(ButtonModel *)model frame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        
        self.buttonModel = model;
        [self setBackgroundColor:[UIColor redColor]];
        [self setTitle:model.name forState:UIControlStateNormal];
    }
    return self;
}

#pragma mark - private Methods
- (CGSize)autoSize:(CGSize)maxSize scaleToSize:(CGSize)orginSize{
    
    if (maxSize.width >= orginSize.width && maxSize.height >=orginSize.height) {
        return orginSize;
    }
    
    CGFloat scaleFactor = 0.0;
    CGFloat scaledWidth = orginSize.width;
    CGFloat scaledHeight = orginSize.height;
    if (CGSizeEqualToSize(maxSize, orginSize) == NO) {
        
        CGFloat widthFactor = orginSize.width / maxSize.width;
        CGFloat heightFactor = orginSize.height / maxSize.height;
        
        if (widthFactor < heightFactor)
            scaleFactor = widthFactor;
        else
            scaleFactor = heightFactor;
        
        scaledWidth  = maxSize.width * scaleFactor;
        scaledHeight = maxSize.height * scaleFactor;
        
        // center the image

    }
    return CGSizeMake(scaledWidth, scaledHeight);
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
